package com.example.serviceadd.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import androidx.annotation.Nullable;

/**
 * Author:LiuZejiang
 * Date:2022/10/23  11:42
 * JDK-Version:1.8
 */
public class Add extends Service {

    private SimplService iBinder;

    // 创建继承Binder的类,直接继承Binder类比继承IBinder省事
    public class SimplService extends Binder {
        public Add service() {
            // 返回当前service
            return Add.this;
        }
        // 加法
        public int add(int a, int b) {
            return (a + b);
        }
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //在服务创建的时候就创建方法
        iBinder = new SimplService();
    }



    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return iBinder;
    }
}
